<script setup lang="ts">
import { ref, reactive } from "vue";
import ReCol from "@/components/ReCol";

const ruleFormRef = ref();

const formRules = reactive({
  Name: [{ required: true, message: "名称为必填项", trigger: "blur" }],
  Code: [{ required: true, message: "编码为必填项", trigger: "blur" }]
});

interface FormItemProps {
  Title?: string;
  Id?: number;
  Name?: string;
  Code?: string;
  Type?: number;
  Qty?: number;
  Status?: number;
}
interface FormProps {
  formInline: FormItemProps;
}

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    Title: "新增",
    Id: 0,
    Name: "",
    Code: "",
    Type: 0,
    Qty: 0,
    Status: 0
  })
});

const newFormInline = ref(props.formInline);

const typeOption = [
  { type: "primary", value: 0, label: "智能仓" },
  { type: "info", value: 1, label: "7寸固定料架" },
  { type: "primary", value: 2, label: "13寸固定料架" },
  { type: "primary", value: 3, label: "固定货架" },
  { type: "primary", value: 4, label: "防潮箱" },
  { type: "primary", value: 5, label: "首套料车" },
  { type: "primary", value: 6, label: "续料车" },
  { type: "primary", value: 7, label: "移动货架" },
  { type: "primary", value: 8, label: "移动料箱" }
];

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-row :gutter="30">
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="名称" prop="Name">
          <el-input
            v-model="newFormInline.Name"
            clearable
            placeholder="请输入名称"
          />
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="编码" prop="Code">
          <el-input
            v-model="newFormInline.Code"
            clearable
            placeholder="请输入编码"
          />
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="设备类型" prop="Value">
          <el-select
            v-model="newFormInline.Type"
            placeholder="请选择设备类型"
            class="w-full"
            clearable
          >
            <el-option
              v-for="(item, index) in typeOption"
              :key="index"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="库存数量">
          <el-input-number
            v-model="newFormInline.Qty"
            class="!w-full"
            :min="0"
            :max="9999"
            controls-position="right"
          />
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>
</template>
